﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;

namespace StockAccessors.Interdin.Model
{
	internal class CfdWebGroup : WebGroup
    {
        #region Properties

        public List<WebCfd> Cfds { get; private set; }

        #endregion

        #region Public Methods

        public CfdWebGroup(XDocument data, DateTime creationTime) : base(data, creationTime)
		{
            Cfds = new List<WebCfd>();

            this.FillStocks(data);
		}

        #endregion

        #region Private Methods

        private void FillStocks(XDocument data)
        {
        	XElement[] groups = data.Descendants("tr").ToArray();

            for (int index = 0; index < groups.Count(); index++)
            {
                if (index > 2 && index < groups.Count() - 1)
                {
                    this.Cfds.Add(new WebCfd(groups[index]) { Acquisition = base.CreationTime });
                }
            }
        }

        #endregion
    }
}
